package app.controller.goods;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import app.model.goods.GoodsBase;
import app.model.goods.GoodsStock;
import app.service.goods.GoodsBaseService;
import base.JsonResult;
import base.PageInfo;

@Controller
@RequestMapping("/goods")
public class GoodsBaseController {
	
	private Logger logger = Logger.getLogger(GoodsBaseController.class);
	
	@Autowired
	private GoodsBaseService goodsBaseService;
	
	@ResponseBody
	@RequestMapping("/queryGoodsBasePage.do")
	public PageInfo queryGoodsBasePage(PageInfo pageInfo,String goodsName){
		return goodsBaseService.queryGoodsBasePage(pageInfo,goodsName);
	}
	
	@ResponseBody
	@RequestMapping("/queryGoodsBaseIndex.do")
	public PageInfo queryGoodsBaseIndex(HttpSession session,PageInfo pageInfo,String goodsName){
		
		return goodsBaseService.queryGoodsBaseIndex(pageInfo,goodsName);
	}
	
	@ResponseBody
	@RequestMapping("/save.do")
	public JsonResult save(GoodsBase goodsBase,GoodsStock goodsStock){
		if(StringUtils.isEmpty(goodsBase.getId())){
			goodsBaseService.saveEntity(goodsBase,goodsStock);
		}else{
			goodsBaseService.updateEntity(goodsBase,goodsStock);
		}
		return new JsonResult("操作成功");
	}
	
	@ResponseBody
	@RequestMapping("/view.do")
	public JsonResult view(String id){
		Map<String, Object> goodsBase = goodsBaseService.queryEntityById(id);
		return new JsonResult("操作成功",goodsBase);
	}
	
	@ResponseBody
	@RequestMapping("/del.do")
	public JsonResult del(String ids){
		goodsBaseService.delEntity(ids);
		return new JsonResult("操作成功");
	}
}
